<?php
if(!defined('DIR_INIT'))exit();

$view_type = $x->get_view_type($ext);
if($view_type!='text') sysmsg('不支持的文件格式');

if(filesize($path) > 1024 * 1024 * 10) sysmsg('文件超过10M无法查看');

$content = file_get_contents($path);
if($content===false) sysmsg('文件读取失败');

$coding = mb_detect_encoding($content,"UTF-8,GBK,GB2312");
if($coding != 'UTF-8'){
    $content = mb_convert_encoding($content, 'UTF-8', $coding);
}

$content = htmlspecialchars($content);

header('Content-Type: text/html; charset=UTF-8');
?><!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8" />
    <title>文本查看器</title>
</head>
<body><style>pre {
    color: white;padding:1em;
    background-color: #111;
    white-space: pre-wrap;
    word-wrap: break-word;
}</style>
<pre id="code">
<?php echo $content; ?>
</pre>
<script src="/app/lib/pre.js"></script>
<script>
let p=document.getElementById("code").innerHTML;
document.getElementById("code").innerHTML=pre(p)
</script>
</body>
</html>